package cn.gok.oa.email.controller;


import cn.gok.oa.email.dto.EmailDto;
import cn.gok.oa.email.entity.Emails;
import cn.gok.oa.email.mapper.MailRecipientsMapper;
import cn.gok.oa.email.service.IEmailsService;
import cn.gok.oa.log.LogAnnotation;
import cn.gok.oa.system.service.ITbUserService;
import cn.gok.oa.util.ResultData;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gok
 * @since 2022-08-09
 */
@RestController
@RequestMapping("/email")
public class EmailsController {
    @Autowired
    ITbUserService iTbUserService;
    @Autowired
    IEmailsService iEmailsService;

    @RequestMapping(value = "/user_list",method = RequestMethod.GET)
    @LogAnnotation("获取收件人列表")
    public ResultData getEmailList(){
        return ResultData.buildData(iTbUserService.emailGetUserList());
    }

    @RequestMapping(value = "/send_email",method = RequestMethod.POST)
    @LogAnnotation("发送邮件")
    @ResponseBody
    public ResultData addEmail(EmailDto emailDto){
        boolean check = false;
        if(emailDto!=null)
            check = iEmailsService.sendEmail(emailDto);
        if (check)
            return ResultData.success();
        else
            return ResultData.fail();
    }

    @RequestMapping(value = "/select_receive",method = RequestMethod.GET)
    @LogAnnotation("获取收件箱")
    public ResultData select_Receive(@Param("id") Integer id){
        return ResultData.buildData(iEmailsService.selectReceive(id));
    }

    @RequestMapping(value = "/select_send",method = RequestMethod.GET)
    @LogAnnotation("获取发件箱")
    public ResultData select_Send(@Param("id") Integer id){
        if(id!=null)
            return ResultData.buildData(iEmailsService.getSend(id));
        else
            return ResultData.fail();
    }

    @RequestMapping(value = "/delete_send",method = RequestMethod.DELETE)
    @LogAnnotation("删除发件箱中的邮件")
    public ResultData delete_Send(@Param("id") Integer id){
        if(iEmailsService.removeById(id))
            return ResultData.success();
        else
            return ResultData.fail();
    }

}